package utils

import chisel3._
import chisel3.util._



class SynFifoWithClk2en[T <: Data](gen: T, entries: Int = 2, pipe: Boolean = false, flow : Boolean = false) 
  extends Queue[T](gen: T, entries: Int, pipe: Boolean , flow : Boolean) 
  {
    val clk2en = IO(Input(Bool()))
    val enq_ptr2 = Counter(entries)
    val ptr2_match = enq_ptr2.value === deq_ptr.value
    val empty2 = ptr2_match & !maybe_full

    io.deq.valid := !empty2

  if (flow) {
    when(empty2) {
      io.deq.bits := io.enq.bits
      do_deq := false.B
      when(io.deq.ready) { do_enq := false.B }
    }
  }


    when(clk2en){
        when(do_enq){
            enq_ptr2.value := Mux(enq_ptr.value === (entries-1).U, 0.U, enq_ptr.value + 1.U)
        }.otherwise{
            enq_ptr2.value := enq_ptr.value
        }
    }
    
    when(flush){
        enq_ptr2.reset()
    }

}